package com.jianjian.gulimall;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.validation.Valid;

/**
 * mybatis-plus
 *
 *
 * 2。配置逻辑删除
 * 1.配置全局的逻辑删除规则
 * 2.配置逻辑删除的组件(高版本省略)
 * 3.给Bean上加上逻辑删除注解@TableLogic
 *
 * 3. JSR303
 * 1)给Bean添加校验注解: javax.validation.constraints。并定义自己的信息提示
 * 2)开启校验功能: controller方法参数里添加 	@Valid
 * 		效果:校验错误以后会有默认的响应;
	@RequestMapping("/save")
	public R save(@Valid @RequestBody BrandEntity brand){
	brandService.save(brand);
	return R.ok();
	}
 *3)给校验的bean后紧跟BindingResult,就可以获取到校验的结果
		@RequestMapping("/save")
		//@RequiresPermissions("product:brand:save")
		public R save(@Valid @RequestBody BrandEntity brand, BindingResult result){
		if (result.hasErrors()){
		Map<String,String> map = new HashMap();
		//获取校验的错误结果
		result.getFieldErrors().forEach((item)->{
		//FieldError 获取到错误提示
		String message = item.getDefaultMessage();
		//获取错误的属性名字
		String field = item.getField();
		map.put(field,message);
		});
		return R.error(400,"提交的数据不合法").put("data",map);
		}else {brandService.save(brand);}
		return R.ok();}
 *
 * 4)分组校验(多场景的复杂校验)
 * 		@NotBlank(message = "品牌名必须填写",groups = {UpdateGroup.class,AddGroup.class})
 *    public R update(@Validated({UpdateGroup.class}) @RequestBody BrandEntity brand)
 *  @Validated({UpdateGroup.class})
 *  默认没有指定分组的校验注解@NotBlank，在分组校验@Validated({UpdateGroup.class})情况下不生效，只会在@Validated生效.
 *
 * 5.自定义校验注解
 * 1)编写一个自定义的校验注解
 * 2)编写一个自定义的校验器
 * 3)关联自定义的校验器和自定义的校验注解
 * @Documented
 * @Constraint(
 *         validatedBy = {ListValueConstraintValidator.class [可以指定多个不同的校验器,适配不同类型的校验]}
 * )
 * @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
 * @Retention(RetentionPolicy.RUNTIME)
 * public @interface ListValue
 *
 *
 * 4.统一的异常处理 @ControllerAdvice
 *	GulimallExceptionControllerAdvice类
 *

 */
@SpringBootApplication
public class GulimallProductApplication {

	public static void main(String[] args) {
		SpringApplication.run(GulimallProductApplication.class, args);
	}

}
